<template>
  <!--
      作者 luoyiming
      时间：2019-10-26
      描述：设置-商城设置
  -->
  <div class="product-add">
    <!--form表单-->
    <el-form size="small" ref="form" :model="form" label-width="150px">
      <!--添加门店-->
      <div class="common-form">提现设置</div>
      <el-form-item label="是否开启">
        <div>
          <el-radio-group v-model="form.is_open">
            <el-radio value="1">开启</el-radio>
            <el-radio value="0">关闭</el-radio>
          </el-radio-group>
        </div>
      </el-form-item>
      <el-form-item
        label="最低提现金额"
        :rules="[{ required: true, message: ' ' }]"
        prop="min_amount"
      >
        <el-input
          v-model="form.min_amount"
          placeholder="最低提现金额"
          class="max-w460"
        ></el-input>
      </el-form-item>
      <el-form-item label="提现方式">
        <el-checkbox-group v-model="form.cash_type">
          <el-checkbox :value="10">微信</el-checkbox>
          <el-checkbox :value="20">支付宝</el-checkbox>
          <el-checkbox :value="30">银行卡</el-checkbox>
        </el-checkbox-group>
        <div class="tips">注：提现方式至少选择一个</div>
      </el-form-item>
      <el-form-item
        label="手续费(%)"
        :rules="[{ required: true, message: ' ' }]"
        prop="deduct"
      >
        <el-input
          v-model="form.deduct"
          placeholder="提现手续费"
          class="max-w460"
          type="number"
          @keyup.native="renumber($event)"
        ></el-input>
      </el-form-item>
      <el-form-item
        label="提现说明"
        :rules="[{ required: true, message: ' ' }]"
        prop="desc"
      >
        <el-input
          type="textarea"
          v-model="form.desc"
          placeholder="提现说明"
          rows="7"
        ></el-input>
      </el-form-item>
      <!--提交-->
      <div class="common-button-wrapper">
        <el-button type="primary" @click="onSubmit" :loading="loading"
          >提交</el-button
        >
      </div>
    </el-form>
  </div>
</template>

<script>
import { cashSetting, cashSet } from "@/api/setting.js";
import { formatModel } from "@/utils/base.js";
export default {
  data() {
    return {
      /*是否正在加载*/
      loading: false,
      /*form表单数据*/
      form: {
        is_open: 0, //是否开启提现
        min_amount: 0.1, //最低提现金额
        cash_type: [],
        deduct: 0, //提现手续费
        desc: "", //提现说明
      },
    };
  },
  created() {
    this.getParams();
  },

  methods: {
    /*获取配置数据*/
    getParams() {
      let self = this;
      cashSetting({}, true)
        .then((res) => {
          console.log(res);
          let vars = res.data.vars.values;
          self.form = formatModel(self.form, vars);
          self.loading = false;
        })
        .catch((error) => {});
    },

    /*提交*/
    onSubmit() {
      let self = this;
      let params = this.form;
      if (params.cash_type.length < 1) {
        ElMessage({
          message: "提现方式至少选择一种！",
          type: "warning",
        });
        return;
      }
      self.loading = true;
      cashSet(params, true)
        .then((data) => {
          self.loading = false;
          ElMessage({
            message: "恭喜你，提现设置成功",
            type: "success",
          });
        })
        .catch((error) => {
          self.loading = false;
        });
    },
    renumber(e) {
      var keynum = window.event ? e.keyCode : e.which;
      var keycar = String.fromCharCode(keynum);
      if (keynum == 189 || keynum == 190 || keynum == 110 || keynum == 109) {
        this.$message.warning("禁止输入小数和负数");
        e.target.value = "";
      }
    },
  },
};
</script>
<style>
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  -webkit-appearance: none;
}

input[type="number"] {
  -moz-appearance: textfield;
}
</style>
